/* The file is saved in UTF-8 codepage.
 * Check: «Stereotype», Section mark-§, Copyright-©, Alpha-α, Beta-β, Smile-☺
 */
package cz.pecinovsky.english.lootp._134_;


import cz.pecinovsky.english.lootp._000_.Run;

import cz.pecinovsky.english.lootp.manager.Mover;


import cz.pecinovsky.english.lootp.manager.CanvasManager_Envelope.               CanvasManager;


import cz.pecinovsky.english.lootp._134_.IModular_134_.IModular;
import cz.pecinovsky.english.lootp._134_.Light_134_.Light;
import cz.pecinovsky.english.lootp._134_.TestUtility_134_.TestUtility;


//import cz.pecinovsky.english.lootp._134_.LightTest_134_   .LightTest;
////////////////////////////////////////////////////////////////////////////////
//%%+  +++++ End of ignored starting test - place for imports +++++
//%I+ >=132z
//
//import cz.pecinovsky.english.lootp.canvasmanager.Mover;
//import cz.pecinovsky.english.lootp.canvasmanager.CanvasManager;
//%I-

import cz.pecinovsky.english.lootp.utility.NamedColor;
import cz.pecinovsky.english.lootp.utility.IO;
import cz.pecinovsky.english.lootp.utility.Position;

import java.util.ArrayList;
import java.util.List;
//%X+ xxxxx Start of the ovejumped text with declaration of the envelope xxxxx
/*******************************************************************************
 *<pre>
 * Předchozí: Není - Toto_je_nově_definovaná_třída
 *
 * Projekt  018z_02_Tvary
 *  + testBlink()
 *
 * Projekt  019z_11_Správce
 *   ~ Třída převedena do projektu ovládaného správcem plátna
 *</pre>
 */
public class LightTest_134_
{ static
//%X- ----- End of the ovejumped text with declaration of the envelope -----


/*******************************************************************************
 * Testovací třída {@code LightTest}  slouží ke komplexnímu otestování
 * třídy {@link LightTest}.
 *
 * @author Rudolf PECINOVSKÝ
 * @version 6.03.2017 — 2010-11-08
 */
public class LightTest extends junit.framework.TestCase
{
    private CanvasManager CM;
    private Light light0;
    private Light lightXY;
    private Light lightXYB;
    private Light lightXYP;
    private Light lightXYPB;
    private Light lightXYPBZ;



//== CONSTANT CLASS ATTRIBUTES =================================================
//== VARIABLE CLASS ATTRIBUTES =================================================
//== STATIC CONSTRUCTOR (CLASS INITIALIZER, STATIC INICITALIZING BLOCK) ========
//== CONSTANT INSTANCE ATTRIBUTES ==============================================
//== VARIABLE INSTANCE ATTRIBUTES ==============================================
//== CLASS GETTERS AND SETTERS =================================================
//== OTHER NON-PRIVATE CLASS METHODS ===========================================

//##############################################################################
//== CONSTUCTORS AND FACTORY METHODS ===========================================

    /***************************************************************************
     * Vytvoří test se zadaným názvem.
     *
     * @param name  Název konstruovaného testu
     */
    public LightTest(String name)
    {
        super(name);
    }



//== PREPARATION AND CLEANING THE FIXTURE ======================================

    /***************************************************************************
     * Inicializace předcházející spuštění každého testu a připravující tzv.
     * přípravek (fixture), což je sada objektů, s nimiž budou testy pracovat.
     */
    @Override
    protected void setUp()
    {
        light0    = new Light();
        lightXY   = new Light(50,  50);
        lightXYB  = new Light(100, 100, NamedColor.RED);
        lightXYP  = new Light( 0, 100, 100);
        lightXYPB = new Light(100,   0, 100, NamedColor.BLUE);
        lightXYPBZ= new Light(150, 150, 150, NamedColor.MAGENTA, NamedColor.NO);

        CM = CanvasManager.getInstance();
        CM.add(light0);
        CM.add(lightXY);
        CM.add(lightXYB);
        CM.add(lightXYP);
        CM.add(lightXYPB);
        CM.add(lightXYPBZ);

        System.out.println("\n====== Instance v přípravku pro " + this +
                           "\n| CM: "        + CM +
                           "\n| light0:    " + light0 +
                           "\n| lightXY:   " + lightXY +
                           "\n| lightXYB:  " + lightXYB +
                           "\n| lightXYM : " + lightXYP +
                           "\n| lightXYMB: " + lightXYPB +
                           "\n| lightXYMB: " + lightXYPBZ +
                           "\n======");
        IO.inform("Lights prepared");
    }


    /***************************************************************************
     * Úklid po testu - tato metoda se spustí po vykonání každého testu.
     */
    @Override
    protected void tearDown()
    {
    }


//== PRIVATE AND AUXILIARY CLASS METHODS =======================================
//== PRIVATE AND AUXILIARY INSTANCE METHODS ====================================

    /***************************************************************************
     * Prohodí pozice zadaných světel a nechá zkontrolovat,
     * zda si světla své pozice doopravdy vyměnila.
     *
     * @param s1 První light
     * @param s2 Druhé light
     */
    private void auxSwapPositions(Light s1, Light s2)
    {
        final int ms = 1000;

        s1.switchOff();
        s2.switchOff();
        IO.pause(ms);

        Position p1 = s1.getPosition();
        s1.setPosition(s2.getPosition());
        s2.setPosition(p1);

        IO.pause(ms);
        s1.switchOn();
        s2.switchOn();

        IO.pause(ms);
    }



//== EMBEDDED TYPES AND INNER CLASSES ==========================================
//== THE TESTS =================================================================
//
//     /***************************************************************************
//      *
//      */
//     public void testXXX()
//     {
//     }


    public void testBlink()
    {
        light0    .switchOff();
        lightXY   .switchOff();
        lightXYB  .switchOff();
        lightXYP  .switchOff();
        lightXYPB .switchOff();
        lightXYPBZ.switchOff();
        IO.pause(500);
        light0    .blink();
        lightXY   .blink();
        lightXYB  .blink();
        lightXYP  .blink();
        lightXYPB .blink();
        lightXYPBZ.blink();
        IO.pause(500);
        light0    .switchOn();
        lightXY   .switchOn();
        lightXYB  .switchOn();
        lightXYP  .switchOn();
        lightXYPB .switchOn();
        lightXYPBZ.switchOn();
    }


    public void testSmoothMovement()
    {
        Mover p = new Mover(10);
        p.moveTo(200,   0, light0);
        p.moveTo(200,  50, lightXY);
        p.moveTo(  0,   0, lightXYPBZ);
        p.moveTo(200, 100, lightXYPB);
        p.moveTo(150,   0, lightXYB);
        p.moveTo(  0, 150, lightXYP);
    }


    public void testPositionSize()
    {
        Position sem = new Position(0, 150);
        int small = 25;
        int big   = 150;

        TestUtility.positionSize(lightXYPBZ, sem, small, big);
        TestUtility.positionSize(lightXYPB,  sem, small, big);
        TestUtility.positionSize(lightXYP,   sem, small, big);
        TestUtility.positionSize(lightXYB,   sem, small, big);
        TestUtility.positionSize(lightXY,    sem, small, big);
        TestUtility.positionSize(light0,     sem, small, big);
    }


    public void testGetColor()
    {
        assertEquals(NamedColor.BLUE, lightXYPB.getColor());
        assertEquals(NamedColor.BLUE, light0.getColor());
    }


    public void testSwapPositions()
    {
        auxSwapPositions(light0,   lightXYPB);
        auxSwapPositions(lightXYB, lightXYP);
        auxSwapPositions(lightXYP, light0);
    }


    public void testSwapPositionsWithCheck()
    {
        TestUtility.swapPositionsWithCheck(light0,   lightXYPB);
        TestUtility.swapPositionsWithCheck(lightXYB, lightXYP);
        TestUtility.swapPositionsWithCheck(lightXYP, light0);
    }

//%A+ >142

    /***************************************************************************
     * Vyzkouší schopnosti komparátoru ve třídě {@link TestUtility}
     * při řazení světel.
     */
    public void testSortList()
    {
        List<IModular> seznam = new ArrayList<IModular>();
        seznam.add(light0);
        seznam.add(lightXY);
        seznam.add(lightXYB);
        seznam.add(lightXYP);
        seznam.add(lightXYPB);
        seznam.add(lightXYPBZ);
        seznam.add(light0);
        TestUtility.seřaďSeznam(seznam);
    }

//%A-
//%X+
     /** */
     public void testFixture() {}
//%X-
}
//%%- ---- Start of the ovejumped text with closing of the envelope ----
//== TESTING CLASSES AND METHODS ===============================================
    private LightTest_134_() {}

    /***************************************************************************
     * Třída, jejíž instance má na starosti úklid mezi jednotlivými testy,
     * který není možno zakomponovat do metody {@code tearDown()},
     * dokud nebudou studenti umět programovat.
     */
    private static class TearDown implements Run.ITD
    {
        /** {@inheritDoc} */
        @Override
        public void cleanUp()
        {
//            Canvas.clearCanvas();
            CanvasManager.getInstance().removeAll();
        }
    }


    /***************************************************************************
     * Test method.
     */
    public static void test()
    {
//        junit.textui.TestRunner.run(suite());
//        junit.textui.TestRunner.run(new Třída("test"));
        Run.tests(LightTest.class,
                new TearDown(),
//                "testFixture",
//                "testBlink",
//                "testPositionSize",
//                "testSmoothMovement",
//                "testSwapPositions",
//                "testSwapPositionsWithCheck",
//                "testSmoothlySwapPositions",
                "testSortList",
                "");
        System.exit(0);
    }
    /** @param args Parametry příkazového řádku - nepoužívané. */
    public static void main(String[] args)  {  test();  }
}
